package thread;

/**
 * @author TaoTaojs
 * @date 2021/2/24 下午11:18
 * <p>Description</p>
 * <h2>功能描述</h2>
 * 测试volatile关键字，如果不加有一定概率输出count = 0
 * <h3>主要功能：</h3>
 * <ol>
 *     <li></li>
 * </ol>
 * <h3>关联类</h3>
 * <p>参考链接：</p>
 * <h2>更新日志</h2>
 * [author]        [time]                      [version]          [desc]
 * TaoTaojs        2021/2/24 下午11:18             V1.0
 */
@SuppressWarnings("ALL")
public class 可见性 {

    private static /*volatile*/ int count = 0;

    public static void main(String[] args) {
        Thread th1 = new Thread(() -> {
            count = 10;
        });
        Thread th2 = new Thread(() -> {
            //极小概率会出现等于0的情况
            System.out.println("count=" + count);
        });
        th1.start();
        th2.start();
    }

}
